package me.pplay.playtalk.activity.setting;

import me.pplay.playtalk.ApplicationTrans;
import me.pplay.playtalk.R;
import me.pplay.playtalk.activity.BaseActivity;
import me.pplay.playtalk.protocol.TpChat;
import me.pplay.playtalk.protocol.bean.TPPrivate;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class SettingPrivacyControlActivity extends BaseActivity implements OnClickListener {
	ImageView set_privacycontrol_searchme_check;
	ImageView set_privacycontrol_showmyinfo_check;
	ImageView set_privacycontrol_account_check;
	Button btn_set_ignorecontactlist;
	TPPrivate tpp;
	TpChat tpChat;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_setting_privacycontrol);
		super.SetOnBackClickListener((ImageButton)findViewById(R.id.btn_back));
		set_privacycontrol_searchme_check = (ImageView) findViewById(R.id.set_privacycontrol_searchme_check);
		set_privacycontrol_showmyinfo_check = (ImageView) findViewById(R.id.set_privacycontrol_showmyinfo_check);
		set_privacycontrol_account_check = (ImageView) findViewById(R.id.set_privacycontrol_account_check);
		btn_set_ignorecontactlist = (Button) findViewById(R.id.btn_set_ignorecontactlist);
		initData();
		clickEvents();
	}

	protected void initData() {
		ApplicationTrans appState = (ApplicationTrans) getApplicationContext();
		tpChat = appState.getTpChat();
		tpp = tpChat.tp_chat_get_private_data();
		if (tpp.getStrgmsg() == 0) {// 关
			set_privacycontrol_account_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.unchecked));
		} else {
			set_privacycontrol_account_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.checked));
		}
		if (tpp.getSrched() == 0)// 关
			set_privacycontrol_searchme_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.unchecked));
		else
			set_privacycontrol_searchme_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.checked));

		if (tpp.getDisinfo() == 0)// 关
			set_privacycontrol_showmyinfo_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.unchecked));
		else
			set_privacycontrol_showmyinfo_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.checked));

	}
	private void clickEvents(){
		set_privacycontrol_searchme_check.setOnClickListener(this);
		set_privacycontrol_showmyinfo_check.setOnClickListener(this);
		set_privacycontrol_account_check.setOnClickListener(this);
		btn_set_ignorecontactlist.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.set_privacycontrol_searchme_check:
			if (tpp.getSrched() == 1)
				set_privacycontrol_searchme_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.unchecked));
			else
				set_privacycontrol_searchme_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.checked));
			tpp.setSrched(tpp.getSrched()==1?0:1);
			tpChat.tp_chat_set_private(tpp);
			break;
		case R.id.set_privacycontrol_showmyinfo_check:
			if (tpp.getDisinfo() == 1)
				set_privacycontrol_showmyinfo_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.unchecked));
			else
				set_privacycontrol_showmyinfo_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.checked));
			tpp.setDisinfo(tpp.getDisinfo()==1?0:1);
			tpChat.tp_chat_set_private(tpp);
			break;
		case R.id.set_privacycontrol_account_check:
			if (tpp.getStrgmsg() == 1) {
				set_privacycontrol_account_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.unchecked));
			} else {
				set_privacycontrol_account_check.setBackgroundDrawable(getResources().getDrawable(R.drawable.checked));
			}
			tpp.setStrgmsg(tpp.getStrgmsg()==1?0:1);
			tpChat.tp_chat_set_private(tpp);
			break;
		case R.id.btn_set_ignorecontactlist:
			Intent intent = new Intent(SettingPrivacyControlActivity.this, IgnoreFriendsActivity.class);
			startActivity(intent);
			break;
		}
	}

}
